import { createRouter, createWebHistory } from 'vue-router';

// 配置路由规则
const routes = [
    {
        path: "/",
        name: "web-index",
        component: () => import("../components/index/web-index"),
        children: [
            {
                path: "",
                name: "index-center",
                component: () => import("../components/index/index-center"),
            },
            {
                path: "second/:cat_name/:t_cat_pk",
                name: "second-center",
                component: () => import("../components/second/second-center"),
                props: route => ({ params: route.params })
            },
            {
                path: "nav/:cat_name/:t_cat_pk",
                name: "nav-center",
                component: () => import("../components/nav/nav-center"),
                props: route => ({ params: route.params }),
                children: [
                    {
                        path: "",
                        name: "nav-right",
                        component: () => import("../components/nav/nav-right"),
                    },
                    {
                        path: ":url/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        alias: "content-list/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        name: "content-list",
                        component: () => import("../components/content/content-list"),
                        props: route => ({ params: route.params }),

                    },
                    {
                        path: ":url/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        alias: "image-list/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        name: "image-list",
                        component: () => import("../components/content/image-list"),
                        props: route => ({ params: route.params })
                    },
                    {
                        path: ":url/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        alias: "video-list/:plant_name/:t_plant_pk/:t_cat_plant_pk",
                        name: "video-list",
                        component: () => import("../components/content/video-list"),
                        props: route => ({ params: route.params })
                    },
                    {
                        path: "row/:plant_name/:t_plant_pk/:t_cat_plant_pk/:t_content_pk",
                        name: "content-row",
                        component: () => import("../components/content/content-row"),
                        props: route => ({ params: route.params }),

                    }
                ]
            }
        ]
    },
    {
        path: "/:pathMatch(.*)*",
        redirect: "/"
    }
]

// 创建路由对象
const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.afterEach(() => {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
})

// 导出路由对象
export default router;